package com.xiaoma.product.controller;

import com.xiaoma.product.entity.BrandEntity;
import com.xiaoma.product.entity.CategoryEntity;
import com.xiaoma.product.service.BrandService;
import com.xiaoma.product.service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import utils.R;

import java.util.Arrays;
import java.util.List;

/**
 * @Author: xiaoma
 * @Date: 2021/7/8 14:31
 * @description:
 */
@RestController
@RequestMapping("product/brand")
@Slf4j
public class BrandController {

    @Autowired
    private BrandService brandService;

    @GetMapping("/queryAll")
    public R queryAll(){
        List<BrandEntity> list = brandService.list(null);
        return R.ok().put("data",list);
    }
    @PostMapping("/delete")
    public  R delete(@RequestBody Long[] ids){
       Boolean flag =brandService.removeByIds(Arrays.asList(ids));
       return  flag?R.ok():R.error();
    }
    @PostMapping("/save")
    public  R save(@RequestBody BrandEntity brandEntity){
        boolean flag = brandService.save(brandEntity);
        return  flag?R.ok():R.error();
    }
    @GetMapping("/queryById/{id}")
    public R queryById(@PathVariable("id") Long id){
        BrandEntity data = brandService.getById(id);
        return R.ok().put("data",data);
    }
    @PostMapping("/update")
    public  R update(@RequestBody BrandEntity brandEntity){
        boolean flag = brandService.updateById(brandEntity);
        return  flag?R.ok():R.error();
    }
}
